<template>
  <div class="zfqk-root">
    <base-table-detail :table-column="tableColumn" :form-filed="formFiled" :mid="mid" :query-list-action="queryListAction" :rules="rules"
                       :submit-data-action="submitDataAction" :submit-before-action="submitBeforeAction" :load-list-before="loadListBefore">

      <template v-slot:form-item>
        <el-form-item label="追肥时间" prop="manureUseDate">
          <el-date-picker
            size="mini"
            v-model="formFiled.manureUseDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="肥料名称" prop="manureName">
          <el-input v-model="formFiled.manureName"></el-input>
        </el-form-item>
        <el-form-item label="施肥量(kg/亩)" prop="manureUseLevel">
          <el-input type="number" v-model="formFiled.manureUseLevel"></el-input>
        </el-form-item>

        <el-form-item label="施肥前" prop="sfq">
          <upload-image :limit="1" v-model="formFiled.sfq"></upload-image>
        </el-form-item>
        <el-form-item label="施肥过程" prop="sfz">
          <upload-image :limit="1" v-model="formFiled.sfz"></upload-image>
        </el-form-item>
        <el-form-item label="施肥后" prop="sfh">
          <upload-image :limit="1" v-model="formFiled.sfh"></upload-image>
        </el-form-item>
      </template>
    </base-table-detail>
  </div>
</template>

<script>
  import { reactive, toRefs, onMounted, ref, watch, computed } from '@vue/composition-api'
  import baseTableDetail from '../components/baseTableDetail'
  import { fertilizerEdit, fertilizerList } from '@/api/industry/cpf'
  import { getDicts } from '@/api/system/dict/data'
  import uploadImage from '@/components/UploadImage'

  export default {
    name: 'zfqk',
    props: {
      mid: {
        type: [String, Number],
        default: 1
      }
    },
    components: {
      uploadImage,
      baseTableDetail
    },
    setup(props, content) {
      let data = reactive({
        tableColumn: [
          { name: '追肥时间', prop: 'manureUseDate', width: 300 },
          { name: '肥料名称', prop: 'manureName' },
          { name: '施肥量', prop: 'manureUseLevel' },
          {
            name: '操作',
            prop: 'operation',
            type: 'slot',
            width: 100
          }],
        rules: {},
        queryListAction: fertilizerList,
        submitDataAction: fertilizerEdit,
        formFiled: {
          manureUseDate: null,
          manureName: null,
          manureUseLevel: null,
          sfq: [],
          sfz: [],
          sfh: []
        },
        wateringTypeDict: []
      })

      const loadDict = async() => {
      }

      const loadListBefore = async(response) => {
        await loadDict()
        return response
      }

      const submitBeforeAction = (requestData) => {
        let req = JSON.parse(JSON.stringify(requestData))
        req.photos = [{ type: 1, ...req.sfq[0] }, { type: 2, ...req.sfz[0] }, { type: 3, ...req.sfh[0] }]
        return req
      }
      onMounted(() => {
      })
      return { ...toRefs(data), submitBeforeAction, loadListBefore }
    }
  }
</script>

<style scoped lang="scss">
  .zfqk-root {

  }
</style>
